Page({
  data: {
    healthData: {
      heartRate: 0,
      bloodPressure: {
        systolic: 0,
        diastolic: 0
      },
      bloodSugar: 0,
      temperature: 0
    },
    loading: false,
    lastUpdateTime: ''
  },

  onLoad() {
    this.getHealthData()
  },

  onShow() {
    // 每次显示页面时刷新健康数据
    this.getHealthData()
  },

  // 获取健康数据
  getHealthData() {
    this.setData({ loading: true })
    
    // 使用模拟数据
    const mockData = {
      heartRate: 75,
      bloodPressure: {
        systolic: 120,
        diastolic: 80
      },
      bloodSugar: 5.6,
      temperature: 36.5
    }

    this.setData({
      healthData: mockData,
      lastUpdateTime: new Date().toLocaleString(),
      loading: false
    })

    /* 注释掉后端请求
    wx.request({
      url: 'YOUR_API_BASE_URL/api/health/data',
      method: 'GET',
      header: {
        'Authorization': `Bearer ${wx.getStorageSync('token')}`
      },
      success: (res) => {
        if (res.data.success) {
          this.setData({
            healthData: res.data.data,
            lastUpdateTime: res.data.updateTime
          })
        } else {
          wx.showToast({
            title: '获取健康数据失败',
            icon: 'none'
          })
        }
      },
      fail: () => {
        wx.showToast({
          title: '网络错误',
          icon: 'none'
        })
      },
      complete: () => {
        this.setData({ loading: false })
      }
    })
    */
  },

  // 查看历史记录
  viewHistory() {
    wx.navigateTo({
      url: '/pages/health/history/history'
    })
  },

  // 手动录入数据
  inputData() {
    wx.navigateTo({
      url: '/pages/health/input/input'
    })
  }
}) 